package org.imlinker;

import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import org.imlinker.core.Core; 

/**
 * 启动类，主要作用是获得程序运行的真实路径。
 * 
 * 初始化并启动Core类，初始化并启动Login类。
 */

final class Linker extends Object {

	public static void main(final String[] args) {

		// Change look and feel
		try {
			// Get system look and feel
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException e1) {
			e1.printStackTrace();
		} catch (InstantiationException e1) {
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			e1.printStackTrace();
		} catch (UnsupportedLookAndFeelException e1) {
			e1.printStackTrace();
		}

		String path = "";

		// 获得imLinker.jar文件所在文件夹
		String linkerClassPath = Linker.class.getResource("").toString();
		if (linkerClassPath.indexOf("imLinker.jar") >= 0) {

			// 打包后的情况
			if (System.getProperty("os.name").startsWith("Linux")) {
				path = linkerClassPath;
				path = path.substring(path.indexOf("/"), path
						.indexOf("imLinker.jar"));
			}

		} else {

			// 编辑代码时的情况
			path = linkerClassPath.substring(linkerClassPath.indexOf("/"),
					linkerClassPath.indexOf("/bin"));
			System.out.println(path);

		}

		Core core = new Core(path);
		core.start();

	}
}
